import axios from '@/service/index'

// 产品详情
export const getProductDetails = p => axios.get('/product/getProductDetails', p)

//微信登录
// export const wxLogin = p => axios.postFormData('/wxLogin', p, 'application/x-www-form-urlencoded')

// 发送验证码
// export const sendCode = p => axios.get('/sendCode', p, {'content-type': 'application/x-www-form-urlencoded'})

// 用户注册
export const register = p => axios.postFormData('/register', p)

// 忘记密码
export const changePwd = p => axios.postFormData('/modifyPassword', p)

// 修改密码
export const changePassword = p => axios.postFormData('/changePassword', p)

// 退出登录 (暂时不需要)
export const logout = p => axios.get('/logout', p)

// 查询邀请码
export const getInvitationCode = p => axios.get('/message/getInvitationCode', p)

// 查询我交易记录
export const getTraderList = p => axios.get('/getTraderList', p)

// 查询根据id查询交易记录
export const getTraderDetail = p => axios.get('/getTraderDetails', p)

// 立即预约
export const productSubscribe = p => axios.get('/message/productSubscribe', p)


// 获取用户openid
export const getOpenId = p => axios.postFormData('/addWxuser', p)

// 获取教师列表
export const getTeacherList = p => axios.post('/api/audition/getAllTeacher')

// 查询在线联系所有课程
// export const getAllCourseOnline = p => axios.get('/api/audition/getAllCourse', p)
export const getAllCourseOnlineType = p => axios.get('/api/audition/getCourseType', p);

// 查询当前用户绑定的学生信息
export const getUserStudent = p => axios.get('/api/getUserStudent', p)

// 查询我的页面用户信息
export const getUserInfo = p => axios.get('/api/getUserInfo', p)

// 获取用户是否已经注册
export const getUserIfRegister = p => axios.get('/wx/login', p)

// 根据学生id查询学生购买的课程
export const getCourseByStudentId = p => axios.get('/api/getCourseByStudentId', p)

// 根据学生id查询学生评价
export const getEvaluateById = p => axios.get('/api/getEvaluateById', p)

// 发送验证码
export const sendCode = p => axios.get('/wx/sendCode', p)

// 报名时的验证码
export const sendReservationCode = p => axios.get('/wx/sendReservationCode', p)

// 用户注册
export const wxLogin = p => axios.postFormData('/wx/register', p, 'application/x-www-form-urlencoded')

// 试听课列表查询
export const getAuditionList = p => axios.get(`/api/audition/getAuditionList?typeId=${p.typeId}&size=${p.size}&current=${p.current}`)

// 首页本周课程列表
export const getCourseWeekList = p => axios.get('/api/getHomeList', p)

// 首页所有课程列表
export const getAllCourselist = p => {
  // 从缓存中获取登录数据
  const loginDataStr = localStorage.getItem('px_login_data')
  let params = p || {}

  if (loginDataStr) {
    try {
      const loginData = JSON.parse(loginDataStr)
      if (loginData.result && loginData.result.depId) {
        // 添加 depId 到请求参数
        params = {
          ...params,
          depId: loginData.result.depId
        }
      }
    } catch (e) {
      console.error('解析登录数据失败:', e)
    }
  }

  return axios.get('/api/getAllCourse', params)
}

// 查询课程日历
export const getCalendarCorse = p => axios.get('/api/getCalendarCorse', p)

// 查询具体day课程列表
export const getCalendarCorseList = p => axios.get('/api/getCalendarCorseList', p)

// 查询老师具体day课程列表
export const getTeacherCalendarCorseList = p => axios.get(`/api/getCorseListByteacher?time=${p.time}`)

// 查询我的课程
export const getConductCorse = p => axios.get('/api/getConductCorse', p)

// 查询学生id查询课堂评价
export const getEvaluateList = p => axios.get('/api/getEvaluateById', p)

// 查询试听课程详情
export const getCourseDetail = p => axios.get('/api/audition/getCourseById', p)

// 预约试听课
export const submitOrder = p => axios.postFormData('/api/audition/addAuditionCourse', p, 'application/x-www-form-urlencoded')

// 订单详情
export const getOrderDetail = p => axios.get('api/getBuyCourseById', p);

// 查询老师课程日历
export const getTeacherCourse = p => axios.get(`/api/getCalendarCorseByTeacher?time=${p.time}`)

// 查询老师消课列表
export const getCancelClassList = p => axios.get(`/api/getCancelClass`, p)

// 根据选择的销课查询学员
export const getCancelStudentList = p => axios.get(`/api/list/schedule?classId=${p.classId}&courseId=${p.courseId}&courseStartime=${p.courseStartime}&counrseEndtime=${p.counrseEndtime}`)

// 指定学员消课
export const cancelStatusClass = p => axios.post('/api/addTeacherCancelClass', p)

// 上传图片
export const uploadFile= p => axios.post('/api/common/upload', p)

// 获取评价详情
export const getEnvDetail = p => axios.get(`/api/getEvaluateInfo?pjId=${p.pjId}`)

// 根据ID获取评价详情
export const getEvaluateDetailById = p => axios.get('/api/getEvaluateDetailById', p)

// 提交评价
export const submitEnv = p => axios.post(`/api/evaluate`, p)

// AI图片解析
export const aiImageAnalysis = p => axios.post('/api/ai/image-analysis', p)

// AI解析图片和视频
export const analyzeImages = p => axios.post('/wx/analyzeImages', p)

// 保存学生信息
export const saveStudentInfo = p => axios.post('/wx/student/save', p)

// 获取学生信息
export const getStudentInfo = p => axios.get('/wx/student/info', p)

// 获取校区列表
export const getCampusList = p => axios.get('/wx/dept/campusList', p)

// 获取商品列表
export const getGoodsList = p => axios.get('/wx/goods/list', p)

// 获取商品详情
export const getGoodsDetail = p => axios.get('/wx/goods/detail', p)

// 购买商品
export const buyGoods = p => axios.post('/wx/purchase/buy', p)

// 根据学生ID获取学生详细信息
export const getStudentById = p => axios.get('/api/getStudentById', p)

// 查询购买历史列表
export const getPurchaseList = p => axios.get('/wx/purchase/list', p)

// 确认收货
export const confirmReceipt = p => axios.post('/wx/purchase/confirmReceipt', p)

// 取消兑换
export const cancelExchange = p => axios.post('/wx/purchase/return', p)

// 获取学生积分记录
export const getStudentPoints = p => axios.get('/api/getStudentPoints', p)

// 获取可跟班学生列表
export const getAvailableFollowStudents = p => axios.get('/api/getAvailableFollowStudents', p)

// 添加临时跟班
export const addTemporaryFollow = p => axios.post('/api/addTemporaryFollow', p)

// 申请请假
export const applyLeave = p => axios.post('/api/applyLeave', p)

// 获取课程详情
export const getClassDetail = p => axios.get('/api/getClassDetail', p)

// 学生请假申请
export const addstudentLeave = p => axios.post('/api/studentLeave', p)

// 学生取消请假申请
export const studentCancelLeave = p => axios.post('/api/studentCancelLeave', p)

// 根据课程编号获取班级列表
export const getCourseScheduleByCourseNumber = p => axios.get('/api/getCourseScheduleByCourseNumber', p)
